﻿using System;
using System.Linq;
using System.Text;
using Crossroad.Utils.Extensions;
using SqlSugar;

namespace Crossroad.OAuth.Model
{
    ///<summary>
    ///oauth2.0访问令牌表
    ///</summary>
    [SugarTable("oauth_access_tokens")]
    public partial class AccessToken : ModelContext
    {
        public AccessToken()
        {
            LoadDefVal();
        }

        public AccessToken(bool loadDef)
        {
            if (loadDef)
                LoadDefVal();
        }

        private void LoadDefVal()
        {
            this.companyId = Convert.ToInt32("0");
        }

        /// <summary>
        /// Desc:公司id
        /// Default:0
        /// Nullable:True
        /// </summary>           
        [SugarColumn(ColumnName = "company_id")]
        public int? companyId { get; set; }

        /// <summary>
        /// Desc:有效期
        /// Default:
        /// Nullable:False
        /// </summary>           
        public int expires { get; set; }

        /// <summary>
        /// Desc:权限范围(应用id)
        /// Default:
        /// Nullable:True
        /// </summary>           
        public string scope { get; set; }

        /// <summary>
        /// Desc:用户id
        /// Default:
        /// Nullable:True
        /// </summary>           
        [SugarColumn(ColumnName = "user_id")]
        public string userId { get; set; }

        /// <summary>
        /// Desc:令牌
        /// Default:
        /// Nullable:False
        /// </summary>           
        [SugarColumn(IsPrimaryKey = true, ColumnName = "access_token")]
        public string accessToken { get; set; }

        /// <summary>
        /// Desc:客户端id
        /// Default:
        /// Nullable:False
        /// </summary>           
        [SugarColumn(ColumnName = "client_id")]
        public string clientId { get; set; }

        #region 扩展字段

        /// <summary>
        /// 有效期
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string expiresText => expires.ToDateTimeStr();

        #endregion

    }
}
